import { Control } from 'react-keeper'
import nattyStorage from 'natty-storage';
import DB from './../../app/db';
import StorageUtils from '../../app/storage'


export default (callback, props)=> {

  console.info({test:'开始'});
  console.info(callback);
  console.info(props);
  if (__LOCAL__) {
    console.info({test:'本地'});
    callback();
  } else {
    console.info({test:'网络'});
    (async () => {
      const userInfo = await StorageUtils.getUserInfo();
      console.info({test:'获取的用户'});
      console.info({test:userInfo});
      if (userInfo) {
        console.info({test:"getUserInfo成功，在判断用户是否"});
        DB.WechatAPI.userIsBinding({openId: userInfo.openId}).then(
          function (content) {
            callback();
          },
          function (error) {
            console.log(error);
            WeixinJSBridge.call('closeWindow');
            Control.go('/bindinghome/userbinding', null)

          });
      } else {
        Control.replace('/bindinghome/userbinding', null)
      }
    })();
  }
}
